<?php /*a:2:{s:53:"G:\project\insure\view\admin\policy\policy_edit.phtml";i:1594043569;s:39:"G:\project\insure\view\admin\base.phtml";i:1594023911;}*/ ?>
<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <title>HQadmin</title>
  <meta name="renderer" content="webkit">
  <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
  <meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
  <link rel="stylesheet" href="/static/hqui/libs/layui/css/layui.css"/>
    <link rel="stylesheet" href="/static/hqui/module/admin.css?v=316"/>
  <link rel="stylesheet" href="/static/css/fonts.css">
  <link rel="stylesheet" href="/static/css/base.css">
  
</head>
<style>
    .layui-form-label{
        width: 100px;
    }
    .layui-input-block {
        margin-left: 130px;
        min-height: 36px
    }
</style>
<body>
<div class="layui-fluid">
    <div class="layui-row layui-col-space15">
        
<link rel="stylesheet" href="/static/dist/basic.min.css" />
<link rel="stylesheet" href="/static/dist/dropzone.min.css" />

<link href="/static/regionCheckBox/regionCheckBox.css" rel="stylesheet" />
<style>
    .layui-tab-content {
        padding: 0;/*layui-tab-content:默认有padding: 10px;的值，因为iframe的绝对定位脱离文档流，所以会存在20px的空白空间*/
    }
    .show-frame {
        top: 50px!important;
        /*默认.layui-layout-admin .layui-body {
            top: 60px;
            bottom: 44px;
        }*/
        overflow: hidden;/*消除浏览器最右边的滚动条*/
    }
    .frame {
        position: absolute;
        padding: 10px;/*与layui-footer隔开一段距离*/
        width: 100%;
        height: 100%;
    }
</style>

<div class="layui-card" style="width: 1000px;max-height:4800px">
    <div class="layui-card-body">
        <form action="<?php echo request()->url(); ?>" class="layui-form" method="post">
            <div class="layui-form-item">
                <label class="layui-form-label">政策名称</label>
                <div class="layui-input-block">
                    <input type="text" name="name" value="<?php echo htmlentities((isset($data['name']) && ($data['name'] !== '')?$data['name']:'')); ?>" autocomplete="off" placeholder="请输入政策名称" class="layui-input">
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">选择机构</label>
                <div class="layui-input-block">
                    <select name="aid" lay-verify="required" id="agency" lay-filter="agency">
                        <?php if(!empty($aid)): ?>
                        <option value="<?php echo htmlentities($aid); ?>"><?php echo htmlentities($aname); ?></option>
                        <?php else: if(is_array($agency) || $agency instanceof \think\Collection || $agency instanceof \think\Paginator): $i = 0; $__LIST__ = $agency;if( count($__LIST__)==0 ) : echo "" ;else: foreach($__LIST__ as $key=>$vo): $mod = ($i % 2 );++$i;?>
                        <option value="<?php echo htmlentities($vo['id']); ?>"><?php echo htmlentities($vo['name']); ?></option>
                        <?php endforeach; endif; else: echo "" ;endif; ?>
                        <?php endif; ?>
                    </select>
                </div>
            </div>

            <div class="layui-form-item">
                <label class="layui-form-label">选择保险公司</label>
                <div class="layui-input-block">
                    <select name="cid" lay-verify="required" id="company" lay-filter="company">
                        <?php if(!empty($cid)): ?>
                             <option value="<?php echo htmlentities($cid); ?>"><?php echo htmlentities($cname); ?></option>
                        <?php else: if(is_array($company) || $company instanceof \think\Collection || $company instanceof \think\Paginator): $i = 0; $__LIST__ = $company;if( count($__LIST__)==0 ) : echo "" ;else: foreach($__LIST__ as $key=>$vo): $mod = ($i % 2 );++$i;?>
                        <option value="<?php echo htmlentities($vo['id']); ?>"><?php echo htmlentities($vo['name']); ?></option>
                        <?php endforeach; endif; else: echo "" ;endif; ?>
                        <?php endif; ?>

                    </select>
                </div>
            </div>

            <div class="layui-form-item">
                <label class="layui-form-label">选择出单方</label>
                <div class="layui-input-block">
                    <select name="bid" lay-verify="required" id="bill">
                        <?php if(!empty($bid)): ?>
                        <option value="<?php echo htmlentities($bid); ?>"><?php echo htmlentities($bname); ?></option>
                        <?php else: if(is_array($bill) || $bill instanceof \think\Collection || $bill instanceof \think\Paginator): $i = 0; $__LIST__ = $bill;if( count($__LIST__)==0 ) : echo "" ;else: foreach($__LIST__ as $key=>$vo): $mod = ($i % 2 );++$i;?>
                        <option value="<?php echo htmlentities($vo['id']); ?>"><?php echo htmlentities($vo['name']); ?></option>
                        <?php endforeach; endif; else: echo "" ;endif; ?>
                        <?php endif; ?>

                    </select>
                </div>
            </div>

            <p style="width: 70px;height: 100px;float: left;padding-top:20px;padding-left:35px;">选择地区</p>
            <div id="regionTest" style="padding-left: 20px;float: left"></div>

            <div class="layui-form-item">
                <label class="layui-form-label">新旧车</label>
                <div class="layui-input-block">
                    <input type="radio" name="car" value="0" title="全部" checked>
                    <input type="radio" name="car" value="1" title="新车" <?php if(isset($data) && $data['car'] == 1): ?>checked<?php endif; ?>>
                    <input type="radio" name="car" value="2" title="旧车" <?php if(isset($data) && $data['car'] == 2): ?>checked<?php endif; ?>>
                </div>
            </div>

            <div class="layui-form-item">
                <label class="layui-form-label">排量</label>
                <div class="layui-input-block">
                    <input type="radio" name="displacement" value="0" title="全部" checked>
                    <input type="radio" name="displacement" value="1" title=">125"  <?php if(isset($data) && $data['displacement'] == 1): ?>checked<?php endif; ?>>
                    <input type="radio" name="displacement" value="2" title="<=125"  <?php if(isset($data) && $data['displacement'] == 2): ?>checked<?php endif; ?>>
                </div>
            </div>

            <div class="layui-form-item">
                <label class="layui-form-label">类型</label>
                <div class="layui-input-block">
                    <input type="radio" name="type" value="0" title="摩托车" checked>
                    <input type="radio" name="type" value="1" title="电动车" <?php if(isset($data) && $data['type'] == 1): ?>checked<?php endif; ?>>
                </div>
            </div>

            <div class="layui-form-item">
                <label class="layui-form-label">摩托车类型</label>
                <div class="layui-input-block">
                    <input type="radio" name="mototype" value="0" title="全部" <?php if(isset($data) && $data['mototype'] == 0): ?>checked<?php endif; ?>>
                    <input type="radio" name="mototype" value="1" title="男装摩托车" <?php if(isset($data) && $data['mototype'] == 1): ?>checked<?php endif; ?>>
                    <input type="radio" name="mototype" value="2" title="女装摩托车" <?php if(isset($data) && $data['mototype'] == 1): ?>checked<?php endif; ?>>
                </div>
            </div>

            <div class="layui-form-item">
                <label class="layui-form-label">商业险结算方式</label>
                <div class="layui-input-block">
                    <select name="commercial_type" lay-verify="required">
                        <option value="0" <?php if(isset($data) && $data['commercial_type'] == 0): ?>checked<?php endif; ?>>保单金额比例(元/单)</option>
                        <option value="1" <?php if(isset($data) && $data['commercial_type'] == 1): ?>checked<?php endif; ?>>每单固定金额(%)</option>
                    </select>
                </div>
            </div>

            <div class="layui-form-item">
                <label class="layui-form-label">商业险佣金值</label>
                <div class="layui-input-block">
                      <input type="text" name="commercial_num" value="<?php echo htmlentities((isset($data['commercial_num']) && ($data['commercial_num'] !== '')?$data['commercial_num']:'')); ?>" autocomplete="off" placeholder="请输入商业险佣金" class="layui-input">
                </div>
            </div>

            <div class="layui-form-item">
                <label class="layui-form-label">交强险结算方式</label>
                <div class="layui-input-block">
                    <select name="compolsury_type" lay-verify="required">
                        <option value="0" <?php if(isset($data) && $data['compolsury_type'] == 0): ?>checked<?php endif; ?>>保单金额比例(元/单)</option>
                        <option value="1" <?php if(isset($data) && $data['compolsury_type'] == 1): ?>checked<?php endif; ?>>每单固定金额(%)</option>
                    </select>
                </div>
            </div>

            <div class="layui-form-item">
                <label class="layui-form-label">交强险佣金值</label>
                <div class="layui-input-block">
                    <input type="text" name="compolsury_num" value="<?php echo htmlentities((isset($data['compolsury_num']) && ($data['compolsury_num'] !== '')?$data['compolsury_num']:'')); ?>" autocomplete="off" placeholder="请输入交强险佣金" class="layui-input">
                </div>
            </div>

            <div class="layui-form-item">
                <label class="layui-form-label">政策开始日期</label>
                <div class="layui-input-block">
                    <input type="text" class="layui-input" id="test1" name="effect_time" value="<?php echo htmlentities((isset($data['effect_time']) && ($data['effect_time'] !== '')?$data['effect_time']:'')); ?>" placeholder="<?php echo htmlentities((isset($data['effect_time']) && ($data['effect_time'] !== '')?$data['effect_time']:'')); ?>">
                </div>
             </div>

            <input name="city" value="<?php echo htmlentities((isset($data['city']) && ($data['city'] !== '')?$data['city']:'')); ?>" hidden="hidden" id="all">
            <input name="isedit" value="<?php echo input('isedit'); ?>" hidden="hidden">
            <?php if(input('isedit') == 1): ?>
            <input value="<?php echo htmlentities($data['id']); ?>" hidden="hidden" name="id">
            <?php endif; ?>
        </form>
        <div class="layui-form-item">
            <div class="layui-input-block">
                <button class="layui-btn" lay-filter="i" id="sub" >保存</button>
            </div>
        </div>

    </div>
</div>

<script type="text/javascript" src="/static/js/jquery.min.js"></script>
<script src="/static/js/clipboard.js"></script>
<script src="/static/dist/dropzone.min.js"></script>
<script type="text/javascript" charset="utf-8" src="/static/ueditor/ueditor.config.js"></script>
<script type="text/javascript" charset="utf-8" src="/static/ueditor/ueditor.all.js"> </script >


    </div>
</div>

<script type="text/javascript" src="/static/hqui/libs/layui/layui.all.js"></script>
<script type="text/javascript" src="/static/js/jquery.min.js"></script>
<script type="text/javascript" src="/static/js/layui.base.js"></script>
<script type="text/javascript" src="/static/hqui/js/common.js?v=316"></script>
<script type="text/javascript">

    //工具函数 将表单里数据 序列化成json对象
    $.fn.serializeJson=function(){
        var serializeObj={};
        var array=this.serializeArray();
        var str=this.serialize();
        $(array).each(function(){
            if(serializeObj[this.name]){
                if($.isArray(serializeObj[this.name])){
                    serializeObj[this.name].push(this.value);
                }else{
                    serializeObj[this.name]=[serializeObj[this.name],this.value];
                }
            }else{
                serializeObj[this.name]=this.value;
            }
        });
        return serializeObj;
    };

    function refreshArea(_formWin){
        var _formWinObj = $("#layui-layer"+_formWin);
        var w = _formWinObj.outerWidth();
        var h = _formWinObj.outerHeight();
        var l = ($(document).width()-w)/2;
        var t = ($(window).height()-h)/2;
        _formWinObj.css({
            "left":l,
            "top":t
        });
    }



    $(document).on('click',"#edit",function(){
        console.log($(this).data('id'));
        console.log($('#editurl').val() + '&id=' + $(this).data('id'));
        layer.open({
            type: 2,
            shade: false,
            area: '1000px',

            maxmin: true,
            content: $('#editurl').val() + '&id=' + $(this).data('id'),
            zIndex: layer.zIndex, //重点1
            success: function(layero, index){
                refreshArea(index);
                var height = $(window.parent.document).height();
                layer.style(index, {
                    height: (height -230) + 'px',
                    top: '10px'
                });
            }
        });
    })

    $('#add').click(function(){
        layer.open({
            type: 2,
            shade: false,
            area: '1000px',

            maxmin: true,
            content: $('#addurl').val(),
            zIndex: layer.zIndex, //重点1
            success: function(layero, index){
                refreshArea(index);
                var height = $(window.parent.document).height();
                layer.style(index, {
                    height: (height -230) + 'px',
                    top: '10px'
                });
            }
        });
    })

    $("#agency").change(function(){
        $('#addurl').val($('#oriaddurl').val());
        $('#editurl').val($('#oriaddurl').val());
        var href = $('#addurl').val();
        href += '&aid='+$(this).val();
        $('#addurl').val(href);

        var href1 = $('#editurl').val();
        href1 += '&aid='+$(this).val();
        $('#editurl').val(href1);
        $.ajax({
            url:'getCompany',
            data:{'id':$(this).val()},
            method:'post',
            success:function(res){
                $('#company').children().remove();
                let data = JSON.parse(res);
                let str = '<option value="">全部</option>';
                for(let i in data){
                    str += ' <option value="'+data[i]['id']+'">'+data[i]['name']+'</option>'
                }
                $('#company').append(str);
            }
        });
    });

    $('#company').change(function(){
        var href = $('#addurl').val();
        href += '&cid='+$(this).val();
        $('#addurl').val(href);

        var href1 = $('#editurl').val();
        href1 += '&cid='+$(this).val();
        $('#eidturl').val(href1);
    })

</script>

<script type="text/javascript" src="/static/js/layui.base.js"></script>

<script>
    $(function () {
        layerresize();
    });


    layui.config({
        base: '/static/' //配置组件存放的基础目录
    }).extend({
        regionCheckBox: 'regionCheckBox/regionCheckBox' //定义组件模块名
    }).use(['regionCheckBox'], function(){
        var $ = layui.$;
        var regionCheckBox = layui.regionCheckBox;

        var arr = $('#all').val().split(',');

        //执行实例
        regionCheckBox.render({
            elem: '#regionTest',
            name: 'region', //input name
            value: arr, //赋初始值
            width: '550px', //默认550px
            border: true, //默认true
            ready: function(){ //初始化完成时执行

            },
            change: function(result){ //点击复选框时执行
                $('#all').val(getAllChecked());
            }
        });

        function getAllChecked(){
            var all = '';
            $("input:checkbox[name='region']:checked").each(function(){
                all += $(this).attr('title') + ',';
            });
            return all.substring(0, all.length-1);
        }

    });

    $('#sub').click(function(){
        if($('input[name="name"]').val() == ''){
            layer.open({
                content: '政策名称必填' //这里content是一个普通的String
            });
            return;
        }

        if($('input[name="compolsury_num"]').val() == ''){
            layer.open({
                content: '交强险佣金值必填' //这里content是一个普通的String
            });
            return;
        }


        if($('input[name="commercial_num"]').val() == ''){
            layer.open({
                content: '商业险佣金值必填' //这里content是一个普通的String
            });
            return;
        }

        if($('input[name="city"]').val() == ''){
            layer.open({
                content: '地区必选' //这里content是一个普通的String
            });
            return;
        }

        if($('input[name="effect_time"]').val() == ''){
            layer.open({
                content: '政策开始日期必选' //这里content是一个普通的String
            });
            return;
        }
        var data = $('form').serializeJson();
        $.ajax({
            url:'policy_add',
            data: data,
            method:'post',
            success:function(res){
                layer.open({
                    content: res.msg, //这里content是一个普通的String
                    end: function(){ //此处用于演示
                        if(res.code == 1){
                            var index = parent.layer.getFrameIndex(window.name); //先得到当前iframe层的索引
                            parent.location.reload();//刷新父页面，注意一定要在关闭当前iframe层之前执行刷新
                            parent.layer.close(index); //再执行关闭
                        }
                    }
                });
            }
        });
    })



    layui.use('form', function(){
        var form = layui.form; //只有执行了这一步，部分表单元素才会自动修饰成功

        form.on('select(agency)', function(data){
            $.ajax({
                url:'getCompany',
                data:{'id':data.value},
                method:'post',
                success:function(res){
                    $('#company').children().remove();
                    let data = JSON.parse(res);
                    let str = '';
                    for(let i in data){
                        str += ' <option value="'+data[i]['id']+'">'+data[i]['name']+'</option>'
                    }
                    $('#company').append(str);
                    form.render();
                }
            });
        });

        form.on('select(company)', function(data){
            $.ajax({
                url:'getBill',
                data:{'id':data.value},
                method:'post',
                success:function(res){
                    $('#bill').children().remove();
                    let data = JSON.parse(res);
                    let str = '';
                    for(let i in data){
                        str += ' <option value="'+data[i]['id']+'">'+data[i]['name']+'</option>'
                    }
                    $('#bill').append(str);
                    form.render();
                }
            });
        });
    });

    layui.use('laydate', function(){
        var laydate = layui.laydate;

        //执行一个laydate实例
        laydate.render({
            elem: '#test1' //指定元素
        });

    });
</script>

</body>
</html>